using System.Collections.Generic;
using Voodoo.Sauce.Internal.VoodooTune;
using Voodoo.Tune.Core;

namespace Voodoo.Sauce.Debugger
{
	public class VoodooTuneSandboxDebugScreen : Screen
	{
		private void Start()
		{
			IEnumerable<Sandbox> debugSandboxes = DebugVTManager.GetDebugSandboxes();
			DebugVTConfiguration debugVTConfiguration = (DebugVTManager.IsDraftDebugConfiguration ? DebugVTManager.DraftDebugConfiguration : DebugVTManager.CurrentDebugConfiguration);
			Button("None", UnselectSandbox);
			CreateRadioGroup();
			foreach (Sandbox item in debugSandboxes)
			{
				Sandbox tempSandbox = item;
				DebugRadioButton debugRadioButton = RadioButton(item.Name, delegate(bool isOn)
				{
					OnToggleChanged(isOn, tempSandbox);
				});
				bool value = debugVTConfiguration.SelectedSandbox?.Id == item.Id;
				debugRadioButton.SetValue(value);
			}
			CloseRadioGroup();
		}

		private void UnselectSandbox()
		{
			DebugVTManager.ClearSandboxes();
			ResetRadioGroups(callCallback: false);
		}

		private void OnToggleChanged(bool isOn, Sandbox sandbox)
		{
			if (isOn)
			{
				DebugVTManager.SelectDebugSandbox(sandbox);
			}
		}
	}
}
